<template>
    <div>
        <div class="bg"></div>
            <div class="topList">
                <router-link to="/appmain" class="topBtn">
                <i class="iconfont arrow-left">&#xe641;</i><span class="courseInteract">课堂互动</span>
                </router-link>
            </div>
            <div class="contentList">
                <div class="courseList">课程列表</div>
                <div class="courseInfo">
                    <div class="courseTitle">
                       <p class="courseNameTitle">课程名称</p>
                       <p class="courseStatuTitle">状态</p>
                    </div>
                   <div class="courseItem" @click="gotoroom(item.Cos_ID,item.Cr_Flag,item.Cos_Name)" v-for="item in courselist" :key="item.Cos_Name"> 
                       <p class="courseName">{{item.Cos_Name}}</p>
                       <p class="courseStatu isprogress"  v-if="item.Cr_Flag==4" >已完成</p>
                       <p class="courseStatu isprogress"  v-else-if="item.Cr_Flag==0" style="color: green">未开始</p>
                       <p class="courseStatu isprogress"  v-else-if="item.Cr_Flag==1" style="color: blue">进行中</p>
                       <p class="courseStatu isprogress"  v-else style="color: red">已结束</p>  
                   </div>
                </div>
            </div>
            <div class="bottombar">
                <router-link to='/appmain'>
                    <img src="../../assets/app/home.png" alt="">
                </router-link>                
            </div>       
    </div>
</template>
<script>
import { MessageBox, Toast } from "mint-ui";
export default {
  data() {
    return {
      dt_id: null, //期数编码
      studentinfo: "", //学员数据
      courselist: [] //课程列表
    };
  },
  //初始化
  mounted() {
    //初始化
    this.getlode();
  },
  //事件
  methods: {
    //初始化数据
    getlode() {
      this.dt_id = localStorage.getItem("dt_id"); //获取课堂编码
      this.studentinfo = JSON.parse(localStorage.getItem("studentinfo")); //学员信息
      this.$axios
        .get("/AppInteract", {
          params: { dt_id: this.dt_id, St_Card: this.studentinfo.St_Card }
        })
        .then(Json => {
          this.courselist = Json.data;
        })
        .catch(err => {
          this.$message.error({
            message: "获取信息失败！请重新登录。。",
            type: "success",
            center: "true",
            offset: 300
          });
        });
    },
    //去互动
    gotoroom(cosid, flag,cosname) {
      if (flag == 1) {
        this.$axios
          .get("/Signin", {
            params: { cosid: cosid, St_Card: this.studentinfo.St_Card }
          })
          .then(Json => {            
            if (Json.data == "no") {//去签到
              MessageBox.confirm("该课程没有签到是否去签到？").then(action => {
                this.$router.push({ name: "singup", params: { couid: cosid,couname:cosname } });  
              });                           
            } else {
              this.$router.push({ name: "interactanswer", params: { id: cosid,dt:Json.data,cosname:cosname } });             
            }
            return flag;
          })
          .catch(err => {
            this.$message.error({
              message: "获取信息失败！请重新登录。。",
              type: "success",
              center: "true",
              offset: 300
            });
          });
      }
      if (flag == 4) {
        this.$message({
          message: "互动已完成！",
          center: "true",
          offset: 300
        });
        return flag;
      }
      if (flag == 2) {
        this.$message({
          message: "对不起！互动已结结束",
          center: "true",
          offset: 300
        });
        return flag;
      }
      if (flag == 0) {
        this.$message({
          message: "互动还未开始！",
          center: "true",
          offset: 300
        });
        return flag;
      }
    }
  }
};
</script>

<style scoped>
.bg {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  /* background-image: linear-gradient( 135deg, #0396FF 10%, #ABDCFF 100%); */
  z-index: -1;
  width: 100%;
  /* height: 10rem; */
  background: #ececec;
}
@font-face {
  font-family: "iconfont"; /* project id 1514769 */
  src: url("//at.alicdn.com/t/font_1514769_lvnalmnmtng.eot");
  src: url("//at.alicdn.com/t/font_1514769_lvnalmnmtng.eot?#iefix")
      format("embedded-opentype"),
    url("//at.alicdn.com/t/font_1514769_lvnalmnmtng.woff2") format("woff2"),
    url("//at.alicdn.com/t/font_1514769_lvnalmnmtng.woff") format("woff"),
    url("//at.alicdn.com/t/font_1514769_lvnalmnmtng.ttf") format("truetype"),
    url("//at.alicdn.com/t/font_1514769_lvnalmnmtng.svg#iconfont") format("svg");
}
.iconfont {
  font-family: "iconfont" !important;
  font-size: 25px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  vertical-align: bottom;
}
.topList {
  height: 11rem;
  width: 100%;
  line-height: 2.5rem;
  /* border:1px solid red; */
  text-align: center;
  font-size: 18px;
  background-image: linear-gradient(135deg, #0396ff 10%, #abdcff 100%);
}
.topBtn {
  text-decoration: none;
  color: white;
  display: inline-block;
  width: 100%;
}
.courseInteract {
  margin-left: -2rem;
}
.arrow-left {
  float: left;
}
.contentList {
  width: 83%;
  margin: -7rem auto;
  /* height: 25rem; */
  /* border:1px solid red; */
  border-radius: 10px;
  background: white;
  padding-bottom: 2rem;
  margin-bottom: 80px;
  padding-left: 10px;
  padding-right: 10px;
}
p {
  margin: 0;
  padding: 0;
}
.courseList {
  border-bottom: 1px solid #e5e5e5;
  padding: 15px 10px;
  text-align: center;
  color: #0396ff;
  font-size: 20px;
}
.courseTitle {
  color: darkorange;
}
.courseTitle,
.courseItem {
  display: flex;
  border-bottom: 1px solid #e5e5e5;
  padding: 10px 5px;
  text-align: center;
  font-size: 16px;
}
p {
  margin: 0;
  padding: 0;
}
.courseNameTitle,
.courseName {
  flex: 3;
}
.courseName {
  color: #a0a0a0;
}
.courseStatuTitle,
.courseStatu {
  flex: 1;
}
.isprogress {
  color: #73d25a;
}
.iscompleted {
  color: #0396ff;
}
.incomplete {
  color: red;
}
.bottombar {
  position: fixed;
  z-index: 900;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  border: 1px solid white;
  height: 50px;
  text-align: center;
  background: #0396ff ;

  box-shadow: 0 1px 0 0 rgba(255, 255, 255, 0.1) inset;
}
.bottombar img {
  background: white;
  padding: 10px;
  border-radius: 50%;
  position: relative;
  /* top: -20px; */
  text-shadow: 0 1px rgba(0, 0, 0, 0.3);
  /* border: 5px solid gray; */
}
</style>
